const elements = document.querySelectorAll(".observer-item");

const observer = new IntersectionObserver(callback);
elements.forEach(ele => {
  ele.classList.add("opaque");
  observer.observe(ele);
});

/**
 * 回调函数
 * @param {IntersectionObserverEntry[]} entries
 * @param {IntersectionObserver} instance
 */
function callback(entries, instance) {
  entries.forEach(entry => {
    if (entry.isIntersecting) {
      const element = entry.target;
      element.classList.remove("opaque");
      element.classList.add("come-in");
      instance.unobserve(element);
    }
  });
}
